package com.telecom.controller.access;

import com.dahuatech.hutool.http.Method;
import com.dahuatech.hutool.json.JSONUtil;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.oauth.http.DefaultClient;
import com.dahuatech.icc.oauth.http.IClient;
import com.dahuatech.icc.oauth.model.v202010.GeneralRequest;
import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
import com.telecom.common.AjaxResult;
import com.telecom.common.HttpsUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/evo-apigw/evo-accesscontrol/1.0.0")
public class AccessBasicContrller {


    //设备树搜索接口
    @PostMapping("/resource/tree/search")
    public AjaxResult resourceTreeSearch() throws ClientException {
        Map<String,Object> map = new HashMap<>();
        map.put("showStatus",true);
        map.put("typeCode","01;0;8;7");
        map.put("hasCheckBox",false);
        map.put("hideEmptyOrg",true);
        map.put("searchKey","455");
        map.put("allowRFID",false);
        map.put("deviceGenre","0");
        map.put("filterDeviceModel","25");

//        GeneralResponse generalResponse = HttpsUtils
//                .iRequest("/evo-apigw/evo-accesscontrol/1.0.0/resource/tree/search", Method.POST, map);

//        System.out.println(generalResponse);

        return AjaxResult.success();
    }

    //添加门组
    @PostMapping("/card/accessControl/doorGroup")
    public AjaxResult cardAccessControlDoorGroup()
    {
        Map<String,Object> map = new HashMap<>();
        map.put("name","门组1");
        map.put("memo","门组1备注");
        map.put("orgCode","1000001$7$0$1");
        List<Map<String,Object>> mapList = new ArrayList<>();
        Map<String,Object> map1 = new HashMap<>();
        map1.put("channelCode","1000001$7$0$0");
        Map<String,Object> map2 = new HashMap<>();
        map2.put("channelCode","1000001$7$0$1");
        mapList.add(map1);
        mapList.add(map2);
        map.put("doorGroupDetail",mapList);

        return AjaxResult.success();
    }

    //删除门组接口
    @PostMapping("/card/accessControl/doorGroup/delete/batch")
    public AjaxResult cardAccessControlDoorGroupDeleteBatch()
    {
        List<Integer> list = new ArrayList<>();
        list.add(2);

        return AjaxResult.success();
    }

    //查询单个门组详情
    @PostMapping("/card/accessControl/doorGroup/2")
    public AjaxResult cardAccessControlDoorGroupById()
    {
        return AjaxResult.success();
    }

    //门组列表查询接口
    @PostMapping("/card/accessControl/doorGroup/bycondition/combined")
    public AjaxResult cardAccessControlDoorGroupByconditionCombined()
    {
        Map<String,Object> map = new HashMap<>();
        map.put("singleCondition","门组1");
        map.put("pageNum",1);
        map.put("pageSize",20);

        return AjaxResult.success();
    }

    //门禁控制-门组分配-修改门组
    @PostMapping("/card/accessControl/doorGroup/update")
    public AjaxResult cardAccessControlDoorGroupUpdate()
    {
        Map<String,Object> map = new HashMap<>();
        map.put("id",2);
        map.put("name","门组2");
        map.put("orgCode","001");
        map.put("memo","门组2");

        List<Map<String,Object>> list1 = new ArrayList<>();
        Map<String,Object> map1 = new HashMap<>();
        map1.put("channelCode","1000003$7$0$0");
        Map<String,Object> map2 = new HashMap<>();
        map2.put("channelCode","1000003$7$0$1");

        map.put("addDoorGroupRelDoorList",list1);

        List<Map<String,Object>> list2 = new ArrayList<>();
        Map<String,Object> map3 = new HashMap<>();
        map3.put("channelCode","1000004$7$0$0");
        Map<String,Object> map4 = new HashMap<>();
        map4.put("channelCode","1000004$7$0$1");

        map.put("deleteDoorGroupRelDoorList",list2);

        return AjaxResult.success();
    }

    //添加常开常闭计划
    @PostMapping("/card/accessControl/channel/openNormallySetting/add")
    public AjaxResult cardAccessControlChannelOpenNormallySettingAdd()
    {
        Map<String,Object> map = new HashMap<>();
        map.put("channelCode","1001687$7$0$0");
        map.put("onlineStatus","OFF");
        map.put("openDoorsPlanId",3);
        map.put("closeDoorsPlanId",4);

        return AjaxResult.success();
    }

    //更新常开常闭计划接口
    @PostMapping("/card/accessControl/channel/openNormallySetting/update")
    public AjaxResult cardAccessControlChannelOpenNormallySettingUpdate()
    {
        Map<String,Object> map = new HashMap<>();
        map.put("channelCode","1001687$7$0$0");
        map.put("onlineStatus","OFF");
        map.put("openDoorsPlanId",3);
        map.put("closeDoorsPlanId",4);

        return AjaxResult.success();
    }

    //删除/批量删除常开常闭计划
    @PostMapping("/card/accessControl/channel/openNormallySetting/delete")
    public AjaxResult cardAccessControlChannelOpenNormallySettingDelete()
    {
        Map<String,Object> map = new HashMap<>();
        map.put("channelCode","1001687$7$0$0");

        return AjaxResult.success();
    }

    //分页查询常开常闭计划
    @PostMapping("/card/accessControl/channel/openNormallySettingRest/bycondition/combined")
    public AjaxResult cardAccessControlChannelOpenNormallySettingRestByconditionCombined()
    {
        Map<String,Object> map = new HashMap<>();
        map.put("pageNum",1);
        map.put("pageSize",20);
        map.put("singleCondition","通道1");

        return AjaxResult.success();
    }

    //添加开门计划
    @PostMapping("/card/accessControl/timeQuantum")
    public AjaxResult cardAccessControlTimeQuantum()
    {
        String s = "{\"monday\":[\"00:30:00-00:45:59\",\"01:00:00-01:15:59\",\"02:15:00-02:30:59\",\"04:30:00-04:45:59\"],\"tuesday\":[\"00:15:00-00:30:59\",\"01:00:00-01:15:59\",\"01:45:00-01:59:59\",\"05:00:00-05:15:59\"],\"wednesday\":[\"00:30:00-00:45:59\",\"02:15:00-02:30:59\",\"00:00:00-00:00:00\",\"00:00:00-00:00:00\"],\"thursday\":[\"02:45:00-02:59:59\",\"00:00:00-00:00:00\",\"00:00:00-00:00:00\",\"00:00:00-00:00:00\"],\"friday\":[\"00:00:00-00:15:59\",\"01:00:00-01:15:59\",\"02:45:00-02:59:59\",\"00:00:00-00:00:00\"],\"saturday\":[\"02:30:00-02:45:59\",\"11:00:00-11:15:59\",\"13:15:00-13:30:59\",\"16:00:00-16:15:59\"],\"sunday\":[\"03:45:00-03:59:59\",\"05:15:00-05:30:59\",\"07:45:00-07:59:59\",\"00:00:00-00:00:00\"]}";
        Map<String,Object> map = new HashMap<>();
        map.put("name","111");
        map.put("memo","222");
        map.put("type",1);
        map.put("detail",s);

        return AjaxResult.success();
    }

    //修改开门计划
    @PostMapping("/card/accessControl/timeQuantum/update")
    public AjaxResult cardAccessControlTimeQuantumUpdate()
    {
        String s = "{\"monday\":[\"00:30:00-00:45:59\",\"01:00:00-01:15:59\",\"02:15:00-02:30:59\",\"04:30:00-04:45:59\"],\"tuesday\":[\"00:15:00-00:30:59\",\"01:00:00-01:15:59\",\"01:45:00-01:59:59\",\"05:00:00-05:15:59\"],\"wednesday\":[\"00:30:00-00:45:59\",\"02:15:00-02:30:59\",\"00:00:00-00:00:00\",\"00:00:00-00:00:00\"],\"thursday\":[\"02:45:00-02:59:59\",\"00:00:00-00:00:00\",\"00:00:00-00:00:00\",\"00:00:00-00:00:00\"],\"friday\":[\"00:00:00-00:15:59\",\"01:00:00-01:15:59\",\"02:45:00-02:59:59\",\"00:00:00-00:00:00\"],\"saturday\":[\"02:30:00-02:45:59\",\"11:00:00-11:15:59\",\"13:15:00-13:30:59\",\"16:00:00-16:15:59\"],\"sunday\":[\"03:45:00-03:59:59\",\"05:15:00-05:30:59\",\"07:45:00-07:59:59\",\"00:00:00-00:00:00\"]}";
        Map<String,Object> map = new HashMap<>();
        map.put("id",2);
        map.put("name","111");
        map.put("memo","222");
        map.put("type",1);
        map.put("detail",s);

        return AjaxResult.success();
    }

    //删除/批量删除 开门计划
    @PostMapping("/card/accessControl/timeQuantum/delete")
    public AjaxResult cardAccessControlTimeQuantumDelete()
    {
        Map<String,Object> map = new HashMap<>();
        List<Integer> list = new ArrayList<>();
        list.add(3);
        list.add(4);
        map.put("ids",list);

        return AjaxResult.success();
    }

    //开门计划分页查询接口
    @PostMapping("/card/accessControl/timeQuantum/1/page")
    public AjaxResult cardAccessControlTimeQuantumPage()
    {
        Map<String,Object> map = new HashMap<>();
        map.put("singleCondition","test1");
        map.put("pageSize",20);

        return AjaxResult.success();
    }

    //根据索引查询开门计划
    @GetMapping("/card/accessControl/timeQuantum/getByIndex/23")
    public AjaxResult cardAccessControlTimeQuantumGetByIndex()
    {

        return AjaxResult.success();
    }










    public static void main(String[] args) throws ClientException {
        IClient iClient = new DefaultClient();
        /**
         * 1、请求地址是统一网关入口，以 /evo-apigw 开头
         * 2、方法参见 @see com.dahuatech.hutool.http.Method
         */
//        Map<String,Object> map = new HashMap<>();

        GeneralRequest generalRequest = new GeneralRequest("/evo-apigw/evo-accesscontrol/1.0.0/resource/tree/search",
                Method.POST);
        Map<String,Object> map = new HashMap<>();
//        map.put("showStatus",true);
        map.put("typeCode","01;0;8;7");
//        map.put("hasCheckBox",false);
//        map.put("hideEmptyOrg",true);
//        map.put("searchKey","455");
//        map.put("allowRFID",false);
//        map.put("deviceGenre","0");
//        map.put("filterDeviceModel","25");

//         set http post body
        generalRequest.body(JSONUtil.toJsonStr(map));
        // set http get method param 例如?name=xiao&mobile=1xxx
//        generalRequest.form("key", "value");
        // set header
        // 发起请求处理应答
        GeneralResponse generalResponse =iClient.doAction(generalRequest, generalRequest.getResponseClass());

        System.out.println("000"+generalResponse.getResult());
    }
}
